let dt = document.querySelector(`.xtx-elevator`);//导航栏
let head = document.querySelector(`.xtx_entry`);
let News = document.querySelector(`.xtx_goods_new`);
let popular = document.querySelector(`.xtx_goods_popular`);
let brand = document.querySelector(`.xtx_goods_brand`);
let category = document.querySelector(`.xtx_goods_category`);
let topic = document.querySelector(`.xtx_goods_topic`);
let tail = document.querySelector(`.xtx_footer`);
let i;
let ul = document.querySelector(`.xtx-elevator-list`);
addEventListener(`scroll`, function () {//滚动获取i
  i = document.documentElement.scrollTop;
  let a = document.querySelector(`.active`);
  if (a) {
    a.classList.remove(`active`);
  }
  position();
})
function position() {//出现
  let x;
  if (i >= head.offsetTop || i <= tail.offsetTop) {
    x = 1;
    if (i >= News.offsetTop && i < popular.offsetTop) {
      document.querySelectorAll(`.xtx-elevator-list li a`)[0].classList.add(`active`);
    } else if (i >= popular.offsetTop && i < brand.offsetTop) {
      document.querySelectorAll(`.xtx-elevator-list li a`)[1].classList.add(`active`);
    } else if (i >= brand.offsetTop && i < topic.offsetTop) {
      document.querySelectorAll(`.xtx-elevator-list li a`)[2].classList.add(`active`);
    } else if (i >= topic.offsetTop) {
      document.querySelectorAll(`.xtx-elevator-list li a`)[3].classList.add(`active`);
    }
  } if (i < head.offsetTop || i > tail.offsetTop) {
    x = 0;
  }
  dt.style.opacity = x;
}
ul.addEventListener(`click`, function (i) {
  let x;
  if (i.target.dataset.name === `new`) {
    x = News.offsetTop;
  } if (i.target.dataset.name === `popular`) {
    x = popular.offsetTop;
  } if (i.target.dataset.name === `brand`) {
    x = brand.offsetTop;
  } if (i.target.dataset.name === `topic`) {
    x = topic.offsetTop;
  }
  window.scrollTo(0, x);
})